package vcp.models;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Observable;

import javax.swing.JOptionPane;

import client.Message;
import control.SimpleClient;
import vcp.common.AbstractModel;

/**
 * Parking Management Model
 *
 */
public class ParkingManagementModel  extends Observable implements PropertyChangeListener {
	protected SimpleClient client = null;
	protected Message msg = null;
	/**
	 * Reset X request
	 * @param arr
	 */
	public void resetX(ArrayList<Object> arr) {
		client = SimpleClient.getInstance();
		client.addPropertyChangeListener(this);
		
		Message msg = new Message(arr,"ResetX");
		 try {
				client.sendToServer(msg);				
		 }
		 catch (Exception ex)
		    {
			 System.out.println(ex.toString()+"->ResetX");
		    }		
	}
	
	/* (non-Javadoc)
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	@Override
	public void propertyChange(PropertyChangeEvent event) {
		if (event.getPropertyName().equals("MessageUpdate")) {			    
		    msg = client.getReturnMsg();
		    if(msg.getMsg().equals("ResetX")&& msg.isStatus()){
		    	JOptionPane.showMessageDialog(null,
		    		    "X reset , lot restarted .....");
		    }else{
		    	JOptionPane.showMessageDialog(null,
		    		    "Couldn't modify parking it contains more than one car...",
		    		    "Error",
		    		    JOptionPane.ERROR_MESSAGE);
		    }
        }
		client.clearPropertyChangeListener();
	}

}
